import { utcToBeijing } from '../../utils';
import { Blog } from '../../blog/entities/blog.entity';
import { Comment } from '../../comment/entities/comment.entity';
import { Daily } from '../../daily/entities/daily.entity';
import { User } from '../../user/entities/user.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity({ name: 'like' })
export class Like {
  @PrimaryGeneratedColumn()
  id: number;

  @CreateDateColumn({
    type: 'timestamp',
    transformer: {
      to(value: Date): number {
        return value ? value.getTime() : null;
      },
      from(value: number) {
        // 将UTC时间转换为北京时间
        return utcToBeijing(value);
      },
    },
  })
  createDate: Date;

  @Column({
    comment: '稿件id',
    nullable: false,
  })
  createId: number;

  @Column({
    comment: '稿件人id',
    nullable: true
  })
  authorId: number;

  @Column({
    comment: '点赞的用户id',
    nullable: true,
  })
  userId: number;

  @Column({
    comment: '点赞业务类型',
    nullable: false,
  })
  type: number; // 0博客文章 1说说 2图片 3评论

  @Column({
    comment: '文章Id',
    nullable: true
  })
  blogId: number

  @Column({
    comment: '说说Id',
    nullable: true
  })
  dailyId: number

  @Column({
    comment: '评论Id',
    nullable: true
  })
  commentId: number

  @Column({
    comment: 'ip',
    nullable: true
  })
  ip: string
  
  @ManyToOne(() => Blog, blogInfo => blogInfo.likes)
  blog: Blog[]

  @ManyToOne(() =>Daily, daily =>daily.likes)
  daily: Daily[]

  @ManyToOne(() => Comment, comment=>comment.likes)
  comment: Comment[]

  @ManyToOne(() => User, (user) => user.likes)
  user: User[];
}
